#include "processor.h"
#include "httprequest.h"
#include "httpresponse.h"
#include "httphandleexecutor.h"
#include "log.h"
#define BUFFER "HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: close\r\nContent-Type: text/html\r\n\r\nHello"

class HttpProcessor : public Processor
{
	public:
		HttpProcessor(){}
		~HttpProcessor(){}
		virtual int Process( Buffer * ptBufReq, Buffer * ptBufRes )
		{
			string httpmsg(ptBufReq->GetByteBuffer(),ptBufReq->GetLimit());
			Log::Debug("###########Request###########\n");
			Log::Debug("%s\n",httpmsg.c_str());
			HttpRequest httpRequest(httpmsg);
			HttpResponse httpResponse;
			HttpHandleExecutor* httpHandleExecutor = HttpHandleExecutor::Create();
			httpHandleExecutor->executor(&httpRequest, &httpResponse);
			Buffer bResponse = httpResponse.ToBuffer();
			ptBufRes->Clear();
			ptBufRes->Append(bResponse.GetByteBuffer(), bResponse.GetLimit());
			bResponse.Append('\0');
			Log::Debug("%s\n", bResponse.GetByteBuffer());
			return 0;
		}
};
